<?php
	class categoryControl extends commonControl{
	//显示栏目的主页面；
		function index(){
			$db = M("category");
			$category = $db -> field("catid,cname,category.sort,pid") ->all();
			$category = arr::channel($category, "catid", "pid", 0,0,2, "&nbsp;&nbsp;");
 			$this->assign("category", $category);
			$this->display();
		}
	//添加栏目页面；
		function add_show(){
			$this->display();
		}
	//添加功能；
		function add(){
			$db = M("category");
			if($db->add()){
				$this->success("添加栏目成功","index");
			}else{
				$this->error("添加栏目失败","add_show");
			}
		}
	//编辑界面；
		function edit_show(){
			$db = M("category");
			$catid = $_GET["catid"];
			$filed = $db -> findall($catid);
			$this -> assign ("field",$filed);
			$this->display();
		}
	//编辑
		function edit(){
			$db = M("category");
			if($db -> save()){
				$this->success("修改栏目成功","index");
			}else{
				$this->success("修改栏目失败","edit_show");
			}
		}
	//删除
		function del(){
			$db = M("category");
			$catid = $_GET["catid"];
			$result = $db -> where("pid='$catid'") -> find();
			if($result){
				$this -> error("请先删除子目录","index");
			}else{
				if($db->del($catid)){
					$this -> success("删除目录成功","index");
				}else{
					$this -> error("删除目录成功","index");
				}
			}
		}
	




	}
?>